package net.siufung.boot.datasource.enums;

import cn.hutool.core.date.DatePattern;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import net.siufung.boot.datasource.rules.IColumnType;
import net.siufung.core.model.IEnum;

/**
 * @author 陈建峰
 * @since 2022/8/11 5:59 下午
 */
@AllArgsConstructor
public enum ColumnTypes implements IColumnType {

    // 基本类型
    BASE_BYTE("byte", null),
    BASE_SHORT("short", null),
    // BASE_CHAR("char", null),
    BASE_INT("int", null),
    BASE_LONG("long", null),
    BASE_FLOAT("float", null),
    BASE_DOUBLE("double", null),
    BASE_BOOLEAN("boolean", null),

    // 包装类型
    BYTE("Byte", null),
    SHORT("Short", null),
    CHARACTER("Character", null),
    STRING("String", null),

    BOOLEAN("Boolean", null),

    INTEGER("Integer", null),
    LONG("Long", null),
    FLOAT("Float", null),
    DOUBLE("Double", null),
    BIG_INTEGER("BigInteger", "java.math.BigInteger"),
    BIG_DECIMAL("BigDecimal", "java.math.BigDecimal"),


    BLOB("Blob", "java.sql.Blob"),
    CLOB("Clob", "java.sql.Clob"),

    BYTE_ARRAY("byte[]", null),
    OBJECT("Object", null),

    DATE("Date", "java.util.Date"),
    DATE_SQL("Date", "java.sql.Date"),
    TIME("Time", "java.sql.Time"),
    TIMESTAMP("Timestamp", "java.sql.Timestamp"),
    LOCAL_DATE("LocalDate", "java.time.LocalDate"),
    LOCAL_TIME("LocalTime", "java.time.LocalTime"),
    YEAR("Year", "java.time.Year"),
    YEAR_MONTH("YearMonth", "java.time.YearMonth"),
    LOCAL_DATE_TIME("LocalDateTime", "java.time.LocalDateTime"),
    INSTANT("Instant", "java.time.Instant");

    @Getter
    @Setter
    private String value;

    @Getter
    @Setter
    private String desc;

    public static ColumnTypes get(String value) {
        return IEnum.get(ColumnTypes.class,
                enums -> enums.getValue().equals(value));
    }

    public static Boolean existDate(String value) {
        return ColumnTypes.DATE.equals(ColumnTypes.get(value))
                    || ColumnTypes.DATE_SQL.equals(ColumnTypes.get(value))
                    || ColumnTypes.TIME.equals(ColumnTypes.get(value))
                    || ColumnTypes.TIMESTAMP.equals(ColumnTypes.get(value))
                    || ColumnTypes.LOCAL_DATE.equals(ColumnTypes.get(value))
                    || ColumnTypes.LOCAL_TIME.equals(ColumnTypes.get(value))
                    || ColumnTypes.YEAR.equals(ColumnTypes.get(value))
                    || ColumnTypes.YEAR_MONTH.equals(ColumnTypes.get(value))
                    || ColumnTypes.LOCAL_DATE_TIME.equals(ColumnTypes.get(value))
                    || ColumnTypes.INSTANT.equals(ColumnTypes.get(value));
    }

    public static String dateFormat(String value) {
        if(ColumnTypes.DATE.getValue().equals(value)
                || ColumnTypes.DATE_SQL.getValue().equals(value)
                || ColumnTypes.TIMESTAMP.getValue().equals(value)
                || ColumnTypes.LOCAL_DATE_TIME.getValue().equals(value)
                || ColumnTypes.INSTANT.getValue().equals(value)){
            return DatePattern.NORM_DATETIME_PATTERN;
        } else if(ColumnTypes.LOCAL_DATE.getValue().equals(value)){
            return DatePattern.NORM_DATE_PATTERN;
        } else if(ColumnTypes.LOCAL_TIME.getValue().equals(value)){
            return DatePattern.NORM_TIME_PATTERN;
        } else if(ColumnTypes.YEAR_MONTH.getValue().equals(value)){
            return DatePattern.NORM_MONTH_PATTERN;
        } else if(ColumnTypes.YEAR.getValue().equals(value)){
            return "yyyy";
        }
        return null;
    }

    public static Boolean existString(String value) {
        return ColumnTypes.STRING.equals(ColumnTypes.get(value));
    }

    public static Boolean existFormatNumber(String value) {
        return ColumnTypes.LONG.equals(ColumnTypes.get(value))
                        || ColumnTypes.FLOAT.equals(ColumnTypes.get(value))
                        || ColumnTypes.DOUBLE.equals(ColumnTypes.get(value))
                        || ColumnTypes.BIG_INTEGER.equals(ColumnTypes.get(value))
                        || ColumnTypes.BIG_DECIMAL.equals(ColumnTypes.get(value));
    }



}
